package com.HW;

import java.util.Scanner;
import java.util.logging.Handler;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @ClassName : Tstrstr
 * @Author : kele
 * @Date: 2023/11/1 21:35
 * @Description : 增强strstr
 */
public class Tstrstr {

    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
//        String tar = sc.nextLine();
//        String str = sc.nextLine();
//        handle(tar, str);

        handle("^", "[\\S]");

    }

    public static void handle(String tar, String str) {

        str = str.replace("\\","\\\\").replace(".", "\\.").replace("*", "\\*").replace("?", "\\?")
                .replace("+", "\\+").replace("|", "\\|").replace("{", "\\{")
                .replace("}", "\\}").replace("-", "\\-").replace("(", "\\(")
                .replace(")", "\\)").replace("^", "\\^")
                .replace("$", "\\$");


        System.out.println(str);

        if (tar == "") {
            System.out.println("-1");
            return;
        }


        Pattern compile = Pattern.compile(str);
        Matcher matcher = compile.matcher(tar);

        if (matcher.find()) {
            System.out.println(matcher.start());
            System.out.println(tar.indexOf(matcher.group()));
        } else {
            System.out.println("-1");
        }
    }
}
